package org.jrs.adaptadorDeJuegos.utiles;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;

public class JuegoUtiles {

        public static Serializable clonarObjetoSerializable(Serializable obj){
            if(obj == null)
                return null;
            try{
                    ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
                ObjectOutputStream oos = new java.io.ObjectOutputStream(baos);
                oos.writeObject(obj);
                ByteArrayInputStream bais=new ByteArrayInputStream(baos.toByteArray());
                ObjectInputStream ois=new ObjectInputStream(bais); 
                return (Serializable)(ois.readObject());
            }catch(Exception ioe){
                Logger.global.log(Level.SEVERE, ioe.getMessage());
            }
            return null; 
        }
        
        public static String matrizToString(int matriz[][]){
                String sTexto="Matriz: {\n";
                for (int n=0;n<matriz.length;n++){
                        sTexto+="{";
                        for (int m=0;m<matriz[n].length;m++){
                                if (m>0){
                                        sTexto+=",";
                                }
                                sTexto+=matriz[n][m];
                        }
                        sTexto+="}\n";
                }
                sTexto+="}";
                return sTexto;
        }
        
}
